#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    int n,a[100001]={0};
    cin>>n;
    int ans=n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    int minx=a[1],maxx=a[n],tmp1=0,tmp2=0;
    for(int i=1;i<=n;i++){
        if(a[i]==minx)++tmp1;
        if(a[i]>minx&&a[i]==a[i+1]){
            ++tmp2;
        }
        if(a[i]>tmp2){
            tmp1=min(tmp1,tmp2);
            ans-=tmp1;
            tmp1=a[i];
            tmp2=tmp1+1;
            continue;
        }
    }
    cout<<max(0,ans)-3;
    fclose(stdin);
    fclose(stdout);
    return 0;
}
